//this class just support mutex operation interface
//use bridge pattern to give low-coupling method
//andycai_sc 2011-04-28

#ifndef GMUTEX_H
#define GMUTEX_H

#include "GParallel/GMutexImpl.h"

class GMutex
{
public:
	GMutex();
	~GMutex();

	void lock();
	void unlock();

private:
	GMutexImpl* m_mutexImp;
};

inline
GMutex::GMutex()
{
	m_mutexImp = GMutexImplCreator::create();
}

inline
GMutex::~GMutex()
{
	if (m_mutexImp != 0)
		delete m_mutexImp;
}

inline
void GMutex::lock()
{
	m_mutexImp->lockImpl();
}

inline
void GMutex::unlock()
{
	m_mutexImp->unlockImpl();
}

class GFastMutex
{
public:
	GFastMutex();
	~GFastMutex();

private:
	GMutex m_mutex;
};

inline
GFastMutex::GFastMutex()
{
	m_mutex.lock();
}

inline
GFastMutex::~GFastMutex()
{
	m_mutex.unlock();
}

#endif
